package day4;

import java.util.*;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main3 {
    public static void main1(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextInt()) { // 注意 while 处理多个 case
            int m = in.nextInt();
            int n = in.nextInt();
            StringBuffer stringBuffer = new StringBuffer();
            if(n <= 9) {
                while(m > 0) {
                    int num = m % n;
                    stringBuffer.append(num);
                    m = m / n;
                }
            }else {
                while(m > 0) {
                    int num = m % n;
                    if(num < 10) {
                        stringBuffer.append(num);
                    }else {
                        // switch(num) {
                        //     case 10:
                        //         stringBuffer.append('A');
                        //         break;
                        //     case 11:
                        //         stringBuffer.append('B');
                        //         break;
                        //     case 12:
                        //         stringBuffer.append('C');
                        //         break;
                        //     case 13:
                        //         stringBuffer.append('D');
                        //         break;
                        //     case 14:
                        //         stringBuffer.append('E');
                        //         break;
                        //     case 15:
                        //         stringBuffer.append('F');
                        //         break;
                        // }
                        int num2 = num - 10;
                        stringBuffer.append(('A'+num2));


                    }
                    m = m / n;
                }
            }
            System.out.println(stringBuffer.toString());
        }
    }
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextInt()) { // 注意 while 处理多个 case
            int m = in.nextInt();
            int n = in.nextInt();
            StringBuilder str = new StringBuilder();
            boolean flg = false;
            String table = "0123456789ABCDEF";
            if(m < 0) {
                m = -m;
                flg = true;
            }
            if(m == 0) {
                str.append('0');
            }
            if (n < 10) {
                while (m > 0) {
                    int num = m % n;
                    str.append(table.charAt(num));
                    m = m / n;
                }
            } else {
                while (m > 0) {
                    int num = m % n;
                    if (num  < 10) {
                        str.append(table.charAt(num));
                    } else {
                        str.append(table.charAt(num));
                    }
                    m = m / n;
                }
            }
            if(flg) {
                str.append('-');
            }
            str.reverse();
            System.out.println(str.toString());
        }
    }
}